  

function getkeyFromHttp()
    -- 获取http请求里的token 随机串
  local key_update= nil
  local arg = ngx.req.get_uri_args()
  for k,v in pairs(arg) do
    if k=="token" then
        key_update=v
     end   
  end
end  

local cjson = require "cjson"
local dyups = require "ngx.dyups"
local redis = require "resty.redis"


local key_update=getkeyFromHttp()
if not key_update then
   ngx.say("failed to getkeyFromHttp: ", err)
   return
end




local redis = redis:new()
redis:set_timeout(1000) -- 1 sec
local ok, err = redis:connect("127.0.0.1", 6379)
if not ok then
   ngx.say("failed to connect: ", err)
   return
end
local key = redis:get(key_update)
 ngx.print(key)
local keyObj = cjson.decode(key) 


local serverlist=keyObj.http_array
ngx.print(serverlist)
local status, rv = dyups.update("host2",serverlist);
if status ~= ngx.HTTP_OK then

   ngx.log(ngx.ERR, "status",status) 
  return
end
ngx.print("update success")